#include <iostream>
using namespace std;
int main()
{
    int  q, l, r;
    cin >> q;
    int arr[4];
    arr[0] = 0;
    int dp[4];
    dp[0] = 0;
    for (int i = 1; i <= 3; i++)
    {
        cin >> arr[i];
        dp[i] = dp[i - 1] + arr[i];

    }
    while (q)
    {
        cin >> l >> r;
        cout << dp[r] - dp[l - 1] << endl;
        q--;
    }
    return 0;
}